def demo01():
    n = int(input())
    flag = 0

    for i in range(n // 8, -1, -1):
        r = n - i * 8
        if r % 6 == 0:
            flag = 1
            print(i + r // 6)
            break
    if flag == 0:
        print(-1)


def demo02():
    """
    https://www.nowcoder.com/practice/5b3184b233f34fb39a7f259ae82eb42c?tpId=385&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3DAI%25E7%25AF%2587%26topicId%3D380
    动态规划：通过 dp_a 和 dp_h 互相依赖，确保序列严格交替。
    :return:
    """
    N = int(input())
    s = input()
    dp_a = 0
    dp_h = 0
    max_dp = 0

    # 这道题是求出小哈笑声的最大长度，不是笑声的长度
    # ,这样每一个循环都要更新一下最长的长度
    for char in s:
        if char == 'a':
            dp_a = dp_h + 1
            dp_h = 0
        elif char == 'h':
            dp_h = dp_a + 1
            dp_a = 0
        else:
            dp_a = 0
            dp_h = 0
        max_dp = max(max_dp, dp_a, dp_h)

    print(max_dp)


if __name__ == '__main__':
    # demo01()
    demo02()
